﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SiteParser.Core
{
	public abstract class HtmlNavigatorBase : IDisposable
	{
		protected TextReader baseReader;

		public HtmlNavigatorBase() { }

		public HtmlNavigatorBase(string filePath) {
			if (string.IsNullOrEmpty(filePath)) {
				throw new ArgumentNullException("filePath");
			}
			if (!File.Exists(filePath)) {
				throw new FileNotFoundException(filePath);
			}

			baseReader = new StreamReader(filePath);
		}

		public HtmlNavigatorBase(TextReader baseReader) {
			if (baseReader == null) {
				throw new ArgumentNullException("baseReader");
			}

			this.baseReader = baseReader;
		}

		public virtual IHtmlIterator Select(HtmlNavigationExpression htmlNavigationExpression) {
			throw new NotImplementedException();
		}

		#region IDisposable Members

		private bool isDisposed = false;

		public void Dispose() {
			Dispose(true);
			GC.SuppressFinalize(this);
		}

		private void Dispose(bool disposing) {
			if (!isDisposed) {
				if (disposing) {
					if (baseReader != null) {
						baseReader.Dispose();
					}
				}

				baseReader = null;
				isDisposed = true;
			}
		}

		#endregion
	}
}
